using UnityEngine;
using System.Collections;

/*!
 * 		\fn s_FirstPersonView
 * 		\brief 	Contient l'ensemble des données et méthodes nécéssaires à la manipulation de 
 * 				la caméra de notre personnage
 */

public class FirstPersonView : MonoBehaviour 
{
	public float alpha					=0.0f;
	public float teta					=0.0f;
	
	public float sensitivityX			=2.0f;
	public float sensitivityY			=2.0f;
	
	public float maxAngleX;
	public float minAngleX;
	
	// Use this for initialization
	
	void Start () 
	{
		maxAngleX=70;
		minAngleX=-70;
	 	alpha					=0.0f;
		teta					=0.0f;
			
		sensitivityX			=2.0f;
		sensitivityY			=2.0f;
			
	}
	
	// Update is called once per frame
	
	void Update () 
	{
		teta+=Input.GetAxis("Mouse X")*sensitivityX;
		alpha-=Input.GetAxis("Mouse Y")*sensitivityY;
		
		if(alpha>maxAngleX)
		{
			alpha=maxAngleX;	
		}
		
		if(alpha<minAngleX)
		{
			alpha=minAngleX;	
		}
		
		transform.rotation= Quaternion.Euler(new Vector3(alpha, teta, 0.0f));
	}
	
	void FixedUpdate()
	{
		if(Character.Instance.m_ObjectGrabed!=null)
		{
			Character.Instance.m_ObjectGrabed.transform.position=transform.position+transform.forward*3.0f;
			Character.Instance.m_ObjectGrabed.rigidbody.velocity=Vector3.zero;
			Character.Instance.m_ObjectGrabed.transform.rigidbody.constraints= RigidbodyConstraints.FreezeRotation;
		}
	}
}
